package gui;

import javax.swing.table.AbstractTableModel;
import ukoly.ProjektControl;
import ukoly.UkolControl;
import ukoly.UkolStatus;
import uzivatele.Uzivatel;

/**
 * Prevzato ze Sunovskeho tutorialu, upraveno
 * @author Pavel Lieberzeit
 */
class UkolTableModel extends AbstractTableModel {
    private String[] columnNames = {"Název", "Popis", "Projekt", "Vlastník", "Status"};
    private UkolControl[] data;

    public UkolTableModel(UkolControl[] data) {
        this.data = data;
    }
    
    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        if(data == null)
            return 0;
        return data.length;
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int row, int col) throws IllegalArgumentException {
        if(data[row] == null)  //nemelo by se stat
            return null;
        switch(col) {
                case 0: return data[row].getModel().getJmeno();
                case 1: return data[row].getModel().getPopis();
                case 2: return data[row].getModel().getProjekt();
                case 3: return data[row].getModel().getVlastnik();
                case 4: return data[row].getModel().getStatus();
                default: IllegalArgumentException up = new IllegalArgumentException();
                         throw up;  //Nemohl jsem si to odpustit
        }
    }

    @Override
    public Class getColumnClass(int c) {
        switch(c) {
                case 0: return String.class;
                case 1: return String.class;
                case 2: return ProjektControl.class;
                case 3: return Uzivatel.class;
                case 4: return UkolStatus.class;
                default: IllegalArgumentException up = new IllegalArgumentException();
                         throw up;  //Nemohl jsem si to odpustit
        }
    }
    public Object getRowModelAt(int row) throws IllegalArgumentException{
        try{
            return data[row];
        }catch (ArrayIndexOutOfBoundsException ex){
            throw new IllegalArgumentException();
        }
        
    }

}